<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>




							<li>
								绩效开始时间：<input type="text" name="startTime"/>
							</li>

							<li>
								绩效结束时间：<input type="text" name="endTime"/>
							</li>

							<li>
								状态：<input type="text" name="status"/>
							</li>


							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="formulate()" shiro:hasPermission="performance:perAppraisalInfo:formulate">
					<i class="fa fa-plus"></i> 制定考核任务
				</a>
				<a class="btn btn-warning btn-del disabled" onclick="enabledEva()" shiro:hasPermission="performance:perAppraisalInfo:enabledEva">
					<i class="fa fa-warning"></i> 开启绩效自评
				</a>

				<a class="btn btn-danger btn-del disabled" onclick="selfEva()" >
					<i class="fa fa-danger"></i> 员工自评
				</a>
				<!--<a class="btn btn-primary btn-del disabled" onclick="viewDetail()" shiro:hasPermission="performance:perAppraisalInfo:viewDetail">
					<i class="fa fa-edit"></i> 查看
				</a>-->
				<a class="btn btn-danger  btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="performance:perAppraisalInfo:remove">
					<i class="fa fa-remove"></i> 删除
				</a>

				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="performance:perAppraisalInfo:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
		var user = [[${@permission.getUserInfo()}]];
        var editFlag = [[${@permission.hasPermi('performance:perAppraisalInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('performance:perAppraisalInfo:remove')}]];
		var leaderEva = [[${@permission.hasPermi('performance:perAppraisalInfo:leaderEva')}]];
		var viewDetail= [[${@permission.hasPermi('performance:perAppraisalInfo:viewDetail')}]];
        var prefix = ctx + "performance/perAppraisalInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'pkid', 
					title : '',
					visible: false
				},
				{
					field : 'name',
					title : '绩效名称',
					sortable: true
				},
				{
					field : 'userName',
					title : '员工',
					sortable: true
				},
				{
					field : 'leaderName',
					title : '打分人',
					sortable: true
				},
				{
					field : 'finalSelfScore', 
					title : '自评得分',
					sortable: true
				},
				{
					field : 'finalLeaderScore', 
					title : '最终得分',
					sortable: true
				},
				{
					field : 'perLevel', 
					title : '绩效等级',
					sortable: true
				},
				{
					field : 'startTime', 
					title : '绩效开始时间',
					sortable: true
				},
				{
					field : 'endTime', 
					title : '绩效结束时间',
					sortable: true
				},
				{
					field : 'statusName',
					title : '状态，',
					sortable: true
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	if(row.status=='enabled'&&row.userId==user.userId){
							actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="evaluation(\'' + row.pkid+','+row.status + '\')"><i class="fa fa-edit"></i>绩效自评</a>');

						}
		            	//绩效评价
						if(row.status=='staffCompleteEvaluation') {
							actions.push('<a class="btn btn-success btn-xs ' + leaderEva + '" href="#" onclick="evaluation(\'' + row.pkid + ',' + row.status + '\')"><i class="fa fa-edit"></i>绩效评价</a>');
						}
						//查看
						if(row.status=='completeEvaluation') {
							actions.push('<a class="btn btn-success btn-xs ' + viewDetail + '" href="#" onclick="viewDetail1(\'' + row.pkid + ',' + row.status + '\')"><i class="fa fa-add"></i>查看详情</a>');
						}

						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.pkid + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

        function enabledEva(){
			var status=$.table.selectColumns('status');
        	for(var i in status){
        		if(status[i]!='disabled'){
                    $.modal.alert('已开启、评价中、已完成的绩效不允许启用！');
                    return;
                }

			}
			$.modal.confirm("确认要要开启员工自评吗？", function() {
				var url = prefix+"/enabledEva";
				var data = { "ids": $.table.selectColumns('pkid').join() };
				$.operate.submit(url, "post", "json", data);
			});
		}

		function selfEva(){
			var status=$.table.selectColumns('status');
			var pkid=$.table.selectColumns('pkid');
			if(status.length>1){
				$.modal.alert('请选择一条记录！');
				return ;
			}
			if(status[0]!='enabled'){
				$.modal.alert('当前状态不能评价！');
				return;
			}
			var userId=$.table.selectColumns('userId')[0];
			if(userId!=user.userId){
				$.modal.alert('员工自评只能评价本人！');
				return;
			}
			$.modal.openTab('绩效考核',prefix+'/evaluation/'+pkid[0]+'?status='+status[0]);
		}
        function formulate(){
			$.modal.open('制定考核任务',prefix+'/formulate',1200,800)
		}

		function evaluation(row){
        	var row=row.split(',');
			$.modal.openTab('绩效考核',prefix+'/evaluation/'+row[0]+'?status='+row[1]);
		}

		function viewDetail1(row){
			var row=row.split(',');
			$.modal.openTab('绩效考核',prefix+'/evaluation/'+row[0]+'?status='+row[1]);
		}
    </script>
</body>
</html>